package cn.example.viewpager;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


public class myViewAdpter extends PagerAdapter {
    private List<View> viewList;
    private List<String> strList;
    public myViewAdpter(List<View> viewList,List<String> str) {
        this.viewList = viewList;
        this.strList=str;
    }
    @Override
    public int getCount() {
        return viewList.size();
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
    /**
     * 初始化
     * @param container
     * @param position
     * @return
     */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(viewList.get(position));
        return viewList.get(position);
    }
    /**
     * 移除组件
     * @param container
     * @param position
     * @param object
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewList.get(position));
    }

    /**
     * 获取标题
     * @param position
     * @return
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return strList.get(position);
    }
}
